#include <iostream>
#include <vector>
#include <cassert>
#include <cstring>

using namespace std;

/**
 * 滑动窗口 求最长字符串长度
 * [O(len(s), O(len(charset)))]	
 */
class Solution{
	public:
		int lengthOfLongestSubstring(string s) {
			int last[256];
			memset(last, -1, sizeof(last));

			int l = 0, r = -1; //滑动窗口为s[l...r]
			int res = 0;
			while(r + 1 < s.size()){

				r ++;
				if(last[s[r]] != -1)
					l = max(l, last[s[r]] + 1);

				res = max(res, r - l + 1);
				last[s[r]] = r;
			}

			return res;
		}

};
